home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
stv.lha
/
STV
/
ISA
/
artifact
/
font.st
< prev
next >
Wrap
Text File
|
1993-07-23
|
7KB
|
221 lines
" Font Enhancements by Tom Wrensch & Gene Korienek
This code will expand the font class with methods for
loading and unloading fonts to disk files. It also
provides for more fonts than the basic three included
with V & V286.
After this code is loaded, do the following to load
in the additional fonts I included: (note: you may
have to change the file pathname)
Font loadFontFrom: (File pathName: 'a:es08.fnt').
Font loadFontFrom: (File pathName: 'a:es10.fnt').
Font loadFontFrom: (File pathName: 'a:es12.fnt').
Font loadFontFrom: (File pathName: 'a:es20.fnt').
To get at these fonts use the Font class message getFont:.
Fonts now have names associated with them, the getFont:
message wants the name (a string) as its argument. To
see the names of the fonts currently in the system do:
Fonts keys
To use these fonts you can set the global variables
TextFont, ListFont, and LabelFont. There is also
SysFont but when changing that you must also change
SysFontHeight, SysFontWidth, and reinitialize the
system and edit menus.
I would be very interested in any other fonts people may
have created."
"evaluate"
Smalltalk at: #Fonts put: Dictionary new!
"evaluate"
Fonts at: 'EightLine' put: Font eightLine!
"evaluate"
Fonts at: 'FourteenLine' put: Font fourteenLine!
"evaluate"
Fonts at: 'SixteenLine' put: Font sixteenLine!
Object subclass: #Font
instanceVariableNames:
'charSize glyphs xTable startChar endChar fixedWidth basePoint '
classVariableNames: ''
poolDictionaries:
'Fonts ' !
!Font class methods !
changeFont: aFont
"Change to font aFont"
TextFont := ListFont := LabelFont := aFont.
self setSysFont: aFont.
ScreenDispatcher initialize.
TextEditor initialize.
TopDispatcher initialize.
Scheduler reinitialize.!
getFont: fontName
"Answer the font with the name fontName (a string)"
^Fonts at: fontName!
loadFontFrom: aStream
"Set up a font load from the stream"
| font fontName |
font := self new.
aStream skipBlanksAndComments.
fontName := font loadNameFrom: aStream.
font loadFontFrom: aStream.
Fonts at: fontName put: font.
^font! !
!Font methods !
loadBooleanFrom: aStream
"Private - Answer the fixedWidth flag from aStream"
^aStream nextLine first = $T!
loadByteFrom: aStream
"Private - Answer a byte value from aStream. Ignore any
'whitespace' characters like Lf, Cr, Space and Tab"
| byte ascii |
ascii := 0.
[ascii < 65] whileTrue: [ascii := aStream next asciiValue].
byte := (ascii - 65) * 16.
ascii := 0.
[ascii < 65] whileTrue: [ascii := aStream next asciiValue].
byte := byte + (ascii - 65).
^byte!
loadFontFrom: aStream
"Private - fill in the font information from aStream"
charSize := self loadPointFrom: aStream.
xTable := self loadXTableFrom: aStream.
startChar := self loadIntegerFrom: aStream.
endChar := self loadIntegerFrom: aStream.
fixedWidth := self loadBooleanFrom: aStream.
basePoint := self loadPointFrom: aStream.
glyphs := self loadFormFrom: aStream.!
loadFormFrom: aStream
"Private - Answer a form loaded from aStream"
| form |
form := Form new.
form extent: (self loadPointFrom: aStream).
(1 to: form bitmap size) do: [:i |
form bitmap at: i put: (self loadByteFrom: aStream)].
^form!
loadIntegerFrom: aStream
"Private - Answer an integer from the stream aStream"
^aStream nextLine asInteger!
loadNameFrom: aStream
"Private - Answer a name (string) from aStream"
^aStream nextLine!
loadPointFrom: aStream
"Private - Answer a point from aStream"
^(self loadIntegerFrom: aStream) @
(self loadIntegerFrom: aStream).!
loadXTableFrom: aStream
"Private - Answer the xTable from aStream. Note that the
xTable is an array of offsets into the glyphs bitmap."
| table |
table := Array new: (self loadIntegerFrom: aStream).
1 to: table size do: [:i |
table at: i put: (self loadIntegerFrom: aStream)].
^table!
unloadBoolean: bool to: aStream
"Private - Put a representation of the boolean value bool
on aStream."
aStream nextPut: (bool ifTrue: [$T] ifFalse: [$F]).
aStream cr.!
unloadByte: aByte to: aStream
"Private - Put a representation of aByte on aStream."
aStream nextPut: ((aByte // 16) + 65) asCharacter.
aStream nextPut: ((aByte rem: 16) + 65) asCharacter.!
unloadFont: fontName to: aStream
"Private - Put a representation of this font on aStream
using the name fontName."
self unloadName: fontName to: aStream.
self unloadPoint: charSize to: aStream.
self unloadXTable: xTable to: aStream.
self unloadInteger: startChar to: aStream.
self unloadInteger: endChar to: aStream.
self unloadBoolean: fixedWidth to: aStream.
self unloadPoint: basePoint to: aStream.
self unloadForm: glyphs to: aStream.!
unloadFontTo: aStream
"Unload this font on the stream aStream. The format
of the file is such that there are no unprintable ascii
characters in the file. This makes it easy to upload
and download the fonts."
| fontName |
Fonts associationsDo: [:a |
a value == self ifTrue: [fontName := a key]].
fontName isNil ifTrue: [fontName := ''].
self unloadFont: fontName to: aStream!
unloadForm: aForm to: aStream
"Private - Put a representation of the aFrom on aStream."
self unloadPoint: aForm extent to: aStream.
aForm bitmap do: [:byte |
self unloadByte: byte to: aStream].!
unloadInteger: anInteger to: aStream
"Private - Put a representation of anInteger on aStream"
anInteger printOn: aStream.
aStream cr.!
unloadName: aString to: aStream
"Private - Put a representation of aString onto aStream.
aString is expected to be a capitialized name."
aStream nextPutAll: aString.
aStream cr.!
unloadPoint: aPoint to: aStream
"Private - Answer a point from aStream"
self unloadInteger: aPoint x to: aStream.
self unloadInteger: aPoint y to: aStream.!
unloadXTable: table to: aStream
"Private - Put a representation of the array xTable on
the stream aStream."
self unloadInteger: table size to: aStream.
table do: [:int |
self unloadInteger: int to: aStream].! !
!FileStream methods !
skipBlanksAndComments
"Skip over blanks, newlines, tabs and comments"
| done next |
done := false.
[done] whileFalse: [
next := self peek.
(next == Space or:
[next == Cr or:
[next == Lf or:
[next == Tab]]])
ifTrue: [self next]
ifFalse: [
next == $"
ifTrue: [self next; skipTo: $"]
ifFalse: [done := true]]]! !